<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
class test extends CI_Controller{
	private $_listeners = array();
	public function __construct(){
		if (ENVIRONMENT!="development")
		{
			show_404();
		}
		parent::__construct();
	}
	
	public function index(){
//		self::demo('Widget::Navigation',$this, 'demo1');
//		self::demo1(1,2,3);
//		self::dete(1,2,3,4);
// 		$tt = get_class($this);
// 		var_dump($tt);
		//var_dump($_SERVER);
		//var_dump(version_compare("1.0.770 rc 1.2","1.0.770 rc 1.0","<="));
		$str =  $this->common->rc4("{\"token\":\"asdfxx31234asdfasdfsadfasdf\",\"time\":1234567893,\"temp\":false,\"session\":true,\"xx\":false}","wowostar123");
		var_dump($str);
	}



	public function phpinfo()
	{
		var_dump(is_https());
		var_dump(site_url(), base_url());
		phpinfo();
	}

	public function demo(){
		//$key = get_class($reference).'->'.$method;
		//$this->_listeners[$hook][$key] = array($reference, $method);
		//$this->load->library('sms');
		//$hahah = $this->sms->send("18664996485","你的验证码是:".rand(0,9).rand(0,9).rand(0,9).rand(0,9));
		//var_dump(explode(",",$hahah));
		//echo strtolower("WOWOWSTAR@www.com");
		//$this->load->service("user_files_service");
		//$name = $this->user_files_service->get_safe_name("测试",array("测试","测试(1)","测试(2)"));
		//var_dump($name);
		//var_dump($_SERVER);exit;
		//phpinfo();
		/*$token = explode("-",strtolower("x-csrf-token"));
		foreach($token as &$v)
		{
			$v=ucwords($v);
		}
		$token = implode("-",$token);
		var_dump($token);*/
		//$data = $this->session->global_destroy("fdfab9d8e1a66abf12d4987aa125a028d295e792");
		//var_dump($data);
		//$_SERVER['REMOTE_ADDR']="12.12.12.12";
		//var_dump($_SERVER);
		$this->load->service("user_verify_service");
		$this->user_verify_service->send_email("hongbinfu@163.com",4);
	}
	
	public function demo1($tes){
		$arg_list = func_get_args();
		for ($i = 0; $i < 3; $i++) {
			echo "Argument $i is: " . $arg_list[$i] . "<br />\n";
		}
	}
	
	public function dete(){
		foreach ($this->_listeners["Widget::Navigation"] as $listener)
		{
			$class  = & $listener[0];
			$method = $listener[1];
		
			if(method_exists($class, $method))
			{
				$args = array_slice(func_get_args(), 1);
					
				$result = call_user_func_array(array($class, $method), $args);
			}
		}
		
//		call_user_func_array(array($class,"me"), array("medd"));
	}
	
	
	public function yyyy(){
		
		$eee = $this->format(1043541823);
		var_dump($eee);
	}
	
	private function format($byte) {
		if ($byte == 0) {
			$byte = 0;
			$unit = "MB";
		} else if ($byte < 1048576) {
			$byte = 1;
			$unit = "MB";
		} else if ($byte < 1073741824) {
			echo "ddd";
			$byte_in_mb = round( $byte / 1048576 );
//			$byte_in_mb = 800;
//			var_dump($byte_in_mb);
			$unit = "MB";
			if ($byte_in_mb >= 1000) {
				$byte = round ( $byte / 1073741824, 2 );
				$unit = "GB";
			} else {
				$byte = $byte_in_mb;
			}
		} else {
			$byte = 1;
			$unit = "GB";
		}
	
		$byte .= $unit;
		return $byte;
	}

	public function haha()
	{
		$data['msg'] = "操作成功";
		$data['title'] = "操作成功";
		$data['type'] = "success";
		$this->template->view('common/message.tpl',$data);
	}

	public function notify()
	{
		$this->template->view("sms_test.tpl");
	}

	public function sms_notify()
	{
		$path = APPPATH.'logs/sms.php';
		if(file_exists($path))
		{
			$content = include_once $path;
			/*$c_content = $this->input->cookie("_SMS_PRE_");
			$c_cont = @json_decode($c_content,TRUE);
			//var_dump($c_cont);
			if(is_array($c_cont) && $c_cont['time']!=$cont['time'])
			{
				$this->input->set_cookie("_SMS_PRE_",$content,0,'','/');
				Common::ajax_return(0,NULL,$cont,FALSE);
			}
			else if($c_cont==FALSE)
			{
				$this->input->set_cookie("_SMS_PRE_","",0,'','/');
			}*/
			//$sess_data = $this->session->userdata("_SMS_TEST_LIST_");
			$pre = $this->input->cookie("_SMS_PRE_");
			if(!is_numeric($pre))
			{
				$pre=0;
			}
			$pre = (int)$pre;
			if(!empty($content) && is_array($content))
			{
				$last = 0;
				$data= array();
				//var_dump($sess_data);
				foreach($content as $k=>$v)
				{
					if($v['time']>$pre)
					{
						if($v['time']>$last)
						{
							$last = $v['time'];
							$data = $v;
						}
					}
				}
				$this->input->set_cookie("_SMS_PRE_",time(),0,'','/');
				if(!empty($data))
				{
					Common::ajax_return(0,NULL,$data,FALSE);
				}
			}
			else
			{
				$this->input->set_cookie("_SMS_PRE_",$pre,0,'','/');
			}
		}
		Common::ajax_return(1004);
		/*$sess_data = $this->session->userdata("_SMS_TEST_LIST_");
		$pre = $this->input->cookie("_SMS_PRE_");
		if(!is_numeric($pre))
		{
			$pre=0;
		}
		$pre = (int)$pre;
		if(!empty($sess_data) && is_array($sess_data))
		{
			$last = 0;
			$data= array();
			//var_dump($sess_data);
			foreach($sess_data as $k=>$v)
			{
				if($v['time']>$pre)
				{
					if($v['time']>$last)
					{
						$last = $v['time'];
						$data = $v;
					}
				}
			}
			$this->input->set_cookie("_SMS_PRE_",time(),0,'','/');
			if(!empty($data))
			{
				Common::ajax_return(0,NULL,$data,FALSE);
			}
		}
		else
		{
			$this->input->set_cookie("_SMS_PRE_",$pre,0,'','/');
		}*/
		//Common::ajax_return(1004);
	}

	public function download()
	{
		$id = $this->input->get("id",true);
		$name = $this->input->get("name",true);
		$test_source = "./resources/file/".$id.".tmp";
		if(file_exists($test_source))
		{
			header('Content-Type:image/gif'); //指定下载文件类型
			header('Content-Disposition: attachment; filename="'.$name.'"'); //指定下载文件的描述
			header('Content-Length:'.filesize($test_source)); //指定下载文件的大小
			//将文件内容读取出来并直接输出，以便下载
			readfile($test_source);
			exit;
		}
		else
		{
			Common::show_message("文件不存在","文件不存在","error","/");
		}
	}

	public function show()
	{
		Common::show_message("haha","神马","error","/",0);
	}

	public function testid()
	{
		echo Common::uniqid()."<br/>";
		echo Common::uniqid()."<br/>";
		echo Common::uniqid()."<br/>";
		echo Common::uniqid()."<br/>";
	}

	public function test_array()
	{
		$a=array("123","dda","3sdf");
		$b=array("123","dda","4333");
		var_dump(array_unique(array_merge($a,$b)));
	}
	public function test_hide(){
		echo Common::hide_email("ab@ss.com");
	}


	public function avatar(){
		$this->load->service("user_info_service");
		echo $this->user_info_service->fetch_remote_avatar("http://qzapp.qlogo.cn/qzapp/101273150/6C61314FD10A39DBB1D5777E76E5F902/30");
	}



	public function params(){
		var_dump($this->input->get());
		var_dump($this->input->post());
	}

	public function time(){
		echo date("Y-m-d H:i:s");
	}
}